import message from "./message";

export const getImageSize = (data: {
  file: File | string;
}): Promise<{ width: number; height: number } | boolean> => {
  return new Promise((reslove) => {
    try {
      const { file } = data;
      if (!file) {
        message.warning("请选择上传的图片");
        reslove(false);
      }
      const image = new Image();

      image.onload = function (e: any) {
        const w = e.target.width;
        const h = e.target.height;

        reslove({ width: w, height: h });
      };
      if (typeof file === "string") {
        image.src = file;
      } else {
        image.src = URL.createObjectURL(file);
      }
    } catch (error: any) {
      message.warning(error);
      reslove(false);
    }
  });
};
